package router

import (
 
	"ser1/app/car"
	"ser1/app/school"

	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

func SetupRouter(r *gin.Engine) {
	// 配置 CORS 中间件
	httpConfig := cors.DefaultConfig()
	httpConfig.AllowAllOrigins = true // 允许所有源
	// httpConfig.AllowOrigins = []string{"http://localhost:8848", "http://localhost:8849"}    // 添加允许的源
	httpConfig.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}           // 允许的 HTTP 方法
	httpConfig.AllowHeaders = []string{"Origin", "Content-Type", "Accept", "Authorization"} // 允许的请求头
	httpConfig.ExposeHeaders = []string{"Content-Length"}                                   // 暴露的响应头
	httpConfig.AllowCredentials = true                                                      // 允许发送 cookies

	r.Use(cors.New(httpConfig))
	// 定义一个静态页面路由
	r.Static("/web", "./web")

	//定义其他静态文件夹
	r.Static("/uploadsA", "./uploads/uploadA")

	// 定义路由分组 /api/v1，用于组织 API 接口
	// demo.RegisterRouter(r)
	// user.RegisterRouter(r)
	// upload.RegisterRouter(r)
	 
	car.RegisterRouter(r)
	school.RegisterRouter(r)
	//r.Use(middleware.Middleware("/login", "/swagger", "/web", "/uploadsA"))

}
